const { con, ResData } = require('./common.js');


async function getAreas(){
  const res = new ResData();
  const sql = 'select * from areas';
  const [rows] = await con.execute(sql);

  return res.data = rows;
}

async function addArea(name){
  const res = new ResData();
  const sql = `insert into areas(area_name) values("${name}")`;
  console.log(sql);
  const [rows] = await con.execute(sql);

  return res.data = rows;

}

async function updateAreas(id,name){
  const res = new ResData();
  const sql = `update areas set area_name='${name}' where id=${id}`;
  console.log(sql);
  const [rows] = await con.execute(sql);
  return res;

}

async  function delArea(id){
  const res = new ResData();
  const sql = `delete from areas where id=${id}`;
  console.log(sql);
  const [rows] = await con.execute(sql);

  return res;

}

module.exports = {
  getAreas,
  addArea,
  updateAreas,
  delArea
};
